package com.jiazhong.shixi.diancan_xitong.controller;


import com.jiazhong.shixi.diancan_xitong.bean.Customer;
import com.jiazhong.shixi.diancan_xitong.mapper.CustomerMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jiazhong.shixi.diancan_xitong.util.JsonResult;
import javax.annotation.Resource;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Resource
    private CustomerMapper customerMapper;
    @RequestMapping("/find")
    public JsonResult find(Customer customer) { //参数
        System.out.println(customer);
        Customer u = customerMapper.login(customer);
        if (u == null) {
            // 登陆失败
            JsonResult result
                    = new JsonResult(false, 427, null, "账号或者密码错误");
            return result;
        } else {
            // 登陆成功，将用户的登录信息给前端送过来
            JsonResult result = new JsonResult(true, 200, u.getId(), "");
            //保存当前的登录信息

            return result;

        }
    }

    @RequestMapping("/add")
    public JsonResult add(Customer customer){
        customerMapper.add(customer);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }

}
